from functools import cache

class Solution:

    def mostPoints(self, questions):
        @cache
        def dfs(i):
            if i >= len(questions):
                return 0

            p, b = questions[i]

            # 选择解决这个问题 和 不解决这个问题的最大值
            return max(p + dfs(i + b + 1), dfs(i + 1))

        return dfs(0)